home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / twinopus / dopus / rename.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1995-07-13  |  3.6 KB  |  152 lines

  1. /*
  2.  *
  3.  * Rename file(s) with TwinExpress from DOpus.
  4.  *
  5.  * (c) 1994 by K.P. van Beem (2:280/464.2, patrick.van.beem@aobh.xs4all.nl)
  6.  *
  7.  * Based on the DOpusLhaARexx package by Geoff Seeley (but you can better
  8.  * use GuiArc in stead of DOpus and a script, to deal with archives)
  9.  *
  10.  *    Mods  By Ray Abram
  11.  *     - If called on a DOpus Dir, then will tell Dopus to do a Rename
  12.  */
  13.  
  14. DOpusPort   = 'DOPUS.1'
  15.  
  16. if ~show(l,"rexxsupport.library") then        
  17.    call addlib("rexxsupport.library",0,-30,0)
  18. if showlist('Ports', DOpusPort) = 0 then do
  19.    say 'Directory Opus Arexx port not found. Aborting.'
  20.    call CleanUp
  21. end
  22.  
  23. address 'DOPUS.1'
  24. options results
  25.  
  26. /* setup DOpus window and tell user what's happening */
  27. Busy on
  28. TopText "Renaming selected files..."
  29.  
  30. /* Get the current path and do file rename */
  31. 'Status 6 -1'
  32. GetEntry Result
  33. FilePath = Result
  34. if left(FilePath,1) ~= '*' then do
  35.    TopText "You are not in a 'Twin' directory. !!"
  36.    Rename
  37.    Busy off
  38.    exit
  39. end
  40.  
  41. FilePath = SubStr(FilePath,2)
  42. GetSelectedAll
  43. SelectedEntries = result
  44. if SelectedEntries = 'RESULT' then do
  45.    TopText "No files selected. ??"
  46.    call CleanUp
  47. end
  48. NumberOfEntries = words(SelectedEntries)
  49. do EntryNumber = 1 to NumberOfEntries
  50.    Index = word(SelectedEntries, EntryNumber)
  51.    GetEntry Index+1
  52.    Entry = result
  53.    File = strip(left(Entry,25))
  54.    getstring '"Rename' File 'as ?"' File
  55.    NewFile = Result
  56.    if NewFile="" | rc~=0 then do
  57.       TopText "You have to specify a new name !!"
  58.       call CleanUp
  59.    end
  60.    if words(Filepath) > 1 then do
  61.       Request "Spaces in a Filename are not Allowed !!"
  62.        exit
  63.    end
  64.  
  65.    SD = EnterDir(FilePath)
  66.    address command 'echo >PPipe: rename' SD || File  SD || NewFile
  67.    selection = Index||' 0 0'
  68.    SelectEntry selection 0 1
  69. end
  70.  
  71. TopText "Ready"
  72. 'DisplayDir -1'
  73. address AREXX "Rexx:DOpus/Reread.rexx"
  74. call CleanUp
  75.  
  76. exit
  77.  
  78. /*---------------------------------------------------------------------------*/
  79.  
  80. CleanUp: /* Remove any files and exit */
  81.    Busy off
  82.    exit
  83. return
  84.  
  85. /*--------------------------------------------------------------------------*/
  86.  
  87. Quote: procedure /* add quotes to string */
  88.    parse arg string
  89. return '"'||string||'"'
  90.  
  91. /*--------------------------------------------------------------------------*/
  92.  
  93. GetWord: procedure /* get word from '|' separated string */
  94.  
  95.   parse arg number,words
  96.  
  97.   if(left(words,1) ~= '|') then
  98.      words = '|'||words
  99.   do i=1 to number
  100.      idx = index(words, '|');
  101.      words = substr(words, idx+1)
  102.   end
  103.   end = index(words, '|') - 1
  104.   if words = "" then
  105.      return ""
  106.   ret_str = substr(words, 1, end)
  107. return ret_str
  108.  
  109. /*--------------------------------------------------------------------------*/
  110.  
  111. CountWords: procedure /* count words from '|' separated string */
  112.  
  113.    parse arg words
  114.  
  115.    count = 0
  116.    idx = index(words, '|')
  117.    do while idx ~= 0
  118.      count = count + 1
  119.      words = substr(words, idx+1)
  120.      idx = index(words, '|')
  121.    end
  122. return count
  123.  
  124. /*--------------------------------------------------------------------------*/
  125.  
  126. /* Cd into the sent Directory path
  127.    - this is needed, as TWIN has a command parameter limit of 30 characters,
  128.       and as we all know AmigaDos file & paths can easily go over this limit !!*/
  129.  
  130. EnterDir: procedure
  131.  
  132.    parse arg Dev ':' Path
  133.  
  134.    /* get the 1st character to address the local or remote machine correctly */
  135.    if left(Dev,1) = '~' then
  136.       sbit = '~'
  137.      else
  138.       sbit = ''
  139.  
  140.    /* does the passed name have a DEVICE in it ? */
  141.    if Dev ~= '' then
  142.       address command 'echo >PPipe: cd' Dev || ':'
  143.  
  144.    do until (t2 = '')
  145.       parse var Path t1 '/' t2
  146.       path = t2
  147.       if t1 ~= '' then
  148.          address command 'echo >PPipe: cd' sbit || t1
  149.    end
  150.  
  151. return sbit
  152.